package com.erp.programmer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.erp.programmer.domain.PurchaseOrderDetail;
import com.erp.programmer.dao.PurchaseOrderDetailMapper;
import com.erp.programmer.dto.PurchaseOrderDetailDto;
import com.erp.programmer.dto.ResponseDto;
import com.erp.programmer.service.IPurchaseOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.erp.programmer.service.ProductService;
import com.erp.programmer.utils.CopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陈鑫
 * @since 2021-05-24
 */
@Service
public class PurchaseOrderDetailServiceImpl extends ServiceImpl<PurchaseOrderDetailMapper, PurchaseOrderDetail> implements IPurchaseOrderDetailService {
    @Autowired
    PurchaseOrderDetailMapper purchaseOrderDetailMapper;
    @Autowired
    ProductService productService;
    @Override
    public ResponseDto<List<PurchaseOrderDetailDto>> getOrderDetail(String purchaseId) {
        QueryWrapper<PurchaseOrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("purchase_id",purchaseId);
        List<PurchaseOrderDetail> purchaseOrderDetailList = purchaseOrderDetailMapper.selectList(queryWrapper);
        List<PurchaseOrderDetailDto> purchaseOrderDetailDtoList = CopyUtil.copyList(purchaseOrderDetailList, PurchaseOrderDetailDto.class);
        for (PurchaseOrderDetailDto purchaseOrderDetailDto:purchaseOrderDetailDtoList) {
            purchaseOrderDetailDto.setProduct(productService.getById(purchaseOrderDetailDto.getProductId()));
        }
        return ResponseDto.success(purchaseOrderDetailDtoList);
    }
}
